﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class morning_StockInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strPage = Request["page"];
            int page = 1;
            try
            {
                page = int.Parse(strPage);
                if (page < 1)
                {
                    page = 1;
                }
            }
            catch (Exception ex)
            {
                page = 1;
            }

            bd(page);
            //var code = Server.UrlDecode(Request["code"]);
            //var sell = Server.UrlDecode(Request["sell"]);
            //var date = Server.UrlDecode(Request["date"]);
            

        }
       
    }
    public int GetPage()
    {
        return AspNetPager1.CurrentPageIndex;
    }


    void bd(int page)
    {
        TemporaryModel.TemporaryEntities dal = DAL.DBManager.GetTempEmtity();
        
        var stockInfo = dal.StockBusinessInfo.AsQueryable();
        var code = Server.UrlDecode(Request["code"]);
        var sell = Server.UrlDecode(Request["sell"]);
        var date = Server.UrlDecode(Request["date"]);
        var userName = Server.UrlDecode(Request["userName"]);

        if(userName!=null)
            stockInfo = stockInfo.Where(x => x.userName==userName);
        if (sell != null)
            stockInfo = stockInfo.Where(x => x.buyOrSell == sell);
        if (code != null)
            stockInfo = stockInfo.Where(x => x.stockCode.Contains(code));
        if (date != null)
        {
            DateTime dt = DateTime.Parse(date);
            stockInfo = stockInfo.Where(x => x.wtDate ==dt);
        }

        AspNetPager1.RecordCount = stockInfo.Count();
        AspNetPager1.CurrentPageIndex = page;
        stockInfo = stockInfo.OrderBy(x => "id").Skip((page - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);
        Repeater1.DataSource = stockInfo;
        Repeater1.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bd(AspNetPager1.CurrentPageIndex);
    }
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        bd(AspNetPager1.CurrentPageIndex);
    }
}